//
//  JFIpoAlertBottomBottomView.m
//  JFStock
//
//  Created by Alan Wang on 2020/3/3.
//  Copyright © 2020 Alan Wang. All rights reserved.
//

#import "JFIpoAlertBottomBottomView.h"
#import <Masonry.h>
#import "JFKitPri.h"

@interface JFIpoAlertBottomBottomView()
AWPButton(cancelBtn)
AWPButton(sureBtn)
@end

@implementation JFIpoAlertBottomBottomView


-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self buildUI];
    }
    return self;
}
-(void)buildUI{
    [self addView];
    [self layoutView];
    [self configStyle];
}
-(void)addView{
    AWAddSelfSubView(self.cancelBtn)
    AWAddSelfSubView(self.sureBtn)
}
-(void)layoutView{
    AWMasFast(self.cancelBtn, {
        AWMasRight(self.mas_centerX, -22.5)
        AWMasCenterY(self, 0)
        AWMasWidth(120)
        AWMasHeight(40)
    })
    AWMasFast(self.sureBtn, {
        AWMasLeft(self.mas_centerX, 22.5)
        AWMasCenterY(self, 0)
        AWMasWidth(120)
        AWMasHeight(40)
    })
}
-(void)configStyle{
    self.backgroundColor = AWThemeColorForKey(@"Global.navBgColor");
}

#pragma mark--辅助方法
-(void)setLeftBtnTitle:(NSString *)leftBtnTitle{
    _leftBtnTitle = leftBtnTitle;
    self.cancelBtn.AWtitle(leftBtnTitle, UIControlStateNormal);
}
-(void)setRightBtnTitle:(NSString *)rightBtnTitle{
    _rightBtnTitle = rightBtnTitle;
    self.sureBtn.AWtitle(rightBtnTitle, UIControlStateNormal);
}
-(void)setStyle:(NSInteger)style{
    if (style == 0) {
        self.cancelBtn.hidden = NO;
        AWMasRemakeFast(self.cancelBtn, {
             AWMasRight(self.mas_centerX, -22.5)
             AWMasCenterY(self, 0)
            AWMasWidth(120)
            AWMasHeight(40)
           })
        AWMasRemakeFast(self.sureBtn, {
            AWMasLeft(self.mas_centerX, 22.5)
            AWMasCenterY(self, 0)
            AWMasWidth(120)
            AWMasHeight(40)
        })
    }else if (style == 1){
          self.cancelBtn.hidden = YES;
          [self.sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
              AWMasCenterX(self, 0)
              AWMasCenterY(self, 0)
              AWMasWidth(160)
              AWMasHeight(40)
          }];
    }
}

-(void)cancelClick:(UIButton*)click{
    if (self.actionBlock) {
        self.actionBlock(0);
    }
}
-(void)sureClick:(UIButton*)btn{
    if (self.actionBlock) {
        self.actionBlock(1);
    }
}

#pragma mark--懒加载
AWLazyGetMethodWithBlock(UIButton, cancelBtn, {
                         tempObject.AWbackgroundColor([UIColor clearColor]).AWborderSet(20, 1, [UIColor colorWithHexString:@"#FC724C"]).AWtitleColor([UIColor colorWithHexString:@"#FC724C"], UIControlStateNormal).AWtitle([JFStringHelper internationalString:@"我知道了"], UIControlStateNormal).AWtitlefont([UIFont fontWithName:@"PingFangSC-Regular" size: 14]).AWclickAction(self, @selector(cancelClick:));
                         })

AWLazyGetMethodWithBlock(UIButton, sureBtn, {
tempObject.AWbackgroundColor([UIColor colorWithHexString:@"#FC724C"]).AWborderSet(20, 1, [UIColor colorWithHexString:@"#FC724C"]).AWtitleColor([UIColor colorWithHexString:@"#ffffff"], UIControlStateNormal).AWtitle([JFStringHelper internationalString:@"前往认购"], UIControlStateNormal).AWtitlefont([UIFont fontWithName:@"PingFangSC-Regular" size: 14]).AWclickAction(self, @selector(sureClick:));
})

@end
